#include<stdio.h>
#include<stdlib.h>
using namespace std;
typedef struct linkList{
    struct linkList *next;
    int data; 
}*link;
link create(link head){
    if(head==NULL){
        head=(link)malloc(sizeof(struct linkList));
        head->data=-1;
        head->next=NULL;  
    }
    int x;
    printf("请输入链表数据（-1结束）:");
    scanf("%d",&x);
    while(x!=-1){
        link node=(link)malloc(sizeof(struct linkList));
        node->data=x;
        node->next=head->next;//头插法
        head->next=node;
        scanf("%d",&x);
    }
    return head;
}
link aaddbLink(link headA){
    link res=headA;
    link q=headA->next->next,p=headA->next;
    while(q){
        link node=(link)malloc(sizeof(struct linkList));
        node->data=p->data+q->data;
        node->next=q;
        p->next=node;
        p=q;
        q=q->next;
    }
    return res;
}
void printList(link head){
    link p=head->next;//头节点存储的-1不是我们输入的
    printf("\n链表结果为：\n");
    while(p){
        printf("%d->",p->data);
        p=p->next;
    }
}
int main(){
    link headA=NULL;
    headA=create(headA);
    printList(headA);
    link resheadA=aaddbLink(headA);
    printf("\n执行aandbList后：\n");
    printList(resheadA);
    return 0;
}